dodule Lockdown
  SESSION_TIMEOUT = 1.hour
  PASSWORD_RESET_TIMEOUT = 24.hour

  module Session
    protected
      def set_session_user(user)
        if user.nil?
          reset_session
          return
        end
        session[:user_id] = user.id
        session[:user_name] =  user.full_name
        session[:user_profile_id] = user.profile.id
				session[:user_client_id] = user.client_id
        session[:permissions] = user.permissions
        if user.user_groups
          session[:user_groups] = user.user_groups.to_syms_from_names
        end
      end
      
      def current_user
       return User.find(current_user_id)
      rescue ActiveRecord::RecordNotFound
       return nil
      end
      
      def current_user_id
       return session[:user_id] || -1
      end

      def current_client_id
       return session[:user_id] || -1
      end
      
      def current_user_name
        session[:user_name]
      end
      
      def current_profile_id
       return session[:user_profile_id] || -1
      end
      
      def current_user_is_admin?
				if session[:user_groups]
					session[:user_groups].include?(:administrators) 
				else
					false
				end
      end
      
      def current_user_is_visitor?
        !logged_in?
      end
  
      def logged_in?
        current_user_id > 0
      end
      
  end # Session module
end # Lockdown module

ActionController::Base.send :include, Lockdown::Session
ActionController::Base.send :helper_method, :logged_in?, 
																						:current_user_name, 
																						:current_user_id, 
																						:current_profile_id 


